package com.guoxin.part4.chapter19;

import java.util.concurrent.TimeUnit;

/**
 * @author guoxin
 * @date 2019/8/31
 */
public class FutureTaskTest {
    public static void main(String[] args) throws InterruptedException {
        //        FutureService<Void, Void> service = FutureService.newService();
        //        Future<?> future = service.submit(() -> {
        //            try {
        //                TimeUnit.SECONDS.sleep(2);
        //            } catch (InterruptedException e) {
        //                e.printStackTrace();
        //            }
        //            System.out.println("I am finish done.");
        //        });
        //        future.get();

        FutureService<String, Integer> service = FutureService.newService();
        Future<Integer> future = service.submint(input -> {
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return input.length();
        }, "hello");
        System.out.println(future.get());
    }
}
